import { EnumBetResult, EnumBjlResult } from "@/models/enums/EnumBjlResult";
import { RecmInfo, RoundInfo } from "../ExecutePlan";
import { IMoneyStrategy } from "../IMoneyStrategy";

export class WithRecmMoneyStrategy implements IMoneyStrategy {
    protected _moneyStrategy: IMoneyStrategy;
    public get moneyStrategy(): IMoneyStrategy {
        return this._moneyStrategy;
    }
    protected _followCount: number = 1;
    protected _reverse: boolean = false;
    constructor(name: string, followCount: number, reverse: boolean, moneyStrategy: IMoneyStrategy) {
        this.strategyName = name;
        this._followCount = followCount;
        this._moneyStrategy = moneyStrategy;
        this._reverse = reverse;
        this.resetStrategy();
    }
    showMoney(): [EnumBjlResult, number] {
        throw new Error("Method not implemented.");
    }
    resetRecm(): void {
        this._moneyStrategy.resetRecm();
    }
    resetStrategy(): void {
        this._moneyStrategy.resetStrategy();
    }
    toMoney(roundInfo: RoundInfo, recmInfo: RecmInfo, userRecm: RecmInfo, baseMoney: number): [EnumBjlResult, number] {
        let recmV = roundInfo.userRecm;
        let recmMoney = 0;
        let followResult = EnumBetResult.NotBet;
        [recmV, recmMoney] = this._moneyStrategy.toMoney(roundInfo, recmInfo, userRecm, baseMoney);
        if (userRecm.summaryInfo.recmResults.length >= this._followCount) {
            followResult = userRecm.summaryInfo.recmResults[userRecm.summaryInfo.recmResults.length - this._followCount];
        }

        if (followResult == EnumBetResult.Success) {
            if (this._reverse) {
                if (roundInfo.userRecm == EnumBjlResult.Z) {
                    recmV = EnumBjlResult.X;
                }
                else if (roundInfo.userRecm == EnumBjlResult.X) {
                    recmV = EnumBjlResult.Z;
                }
                else {
                    recmV = EnumBjlResult.U;
                }
            }
            else {
                recmV = roundInfo.userRecm;
            }
        }
        else if (followResult == EnumBetResult.Fail) {
            if (this._reverse) {
                recmV = roundInfo.userRecm;
            }
            else {
                if (roundInfo.userRecm == EnumBjlResult.Z) {
                    recmV = EnumBjlResult.X;
                }
                else if (roundInfo.userRecm == EnumBjlResult.X) {
                    recmV = EnumBjlResult.Z;
                }
                else {
                    recmV = EnumBjlResult.U;
                }
            }
        }
        else {
            recmV = EnumBjlResult.U;
        }

        return [recmV, recmMoney];
    }
    strategyName: string;
    debugCompoenent: string = "";
    copyValue(valueObj: any): void {
        let obj = valueObj as WithRecmMoneyStrategy;
        if (obj) {
            //复制
            this._moneyStrategy.copyValue(obj._moneyStrategy);
        }
    }

}